import { strict as assert } from 'node:assert';
import { By, until } from 'selenium-webdriver';
import { describe, it, before, after } from 'mocha';
import { createDriver, BASE_URL, ensureServerUp } from './setup.mjs';
import { login, waitForElement } from './common.mjs';

describe('用户管理页面 E2E', function () {
  this.timeout(60000);
  let driver;

  before(async function () {
    await ensureServerUp(60000);
    driver = await createDriver();
    await driver.manage().setTimeouts({
      implicit: 0,
      pageLoad: 60000,
      script: 30000
    });
    await login(driver);
  });

  after(async function () {
    if (driver) {
      await driver.quit();
    }
  });

  it('应加载用户管理页面并展示标题', async function () {
    await driver.get(`${BASE_URL}/user`);
    
    // 等待页面标题加载
    const title = await driver.wait(
      until.elementLocated(By.xpath("//h2[contains(., '用户') or contains(., '成员')]")),
      15000,
      '未找到页面标题'
    );
    
    assert.ok(await title.isDisplayed(), '用户管理标题应显示');
  });

  it('应显示用户列表或空状态', async function () {
    await driver.get(`${BASE_URL}/user`);
    await driver.sleep(2000);
    
    const content = await driver.getPageSource();
    assert.ok(content.length > 0, '用户管理页面应有内容');
  });
});

